package org.sdnstproject.interlayer.openflowfuzzing;
import java.util.StringTokenizer;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class ResultAnalyzer {
	private static final Logger log = LoggerFactory.getLogger(ResultAnalyzer.class);
    public static final int LATENCY_TIME     = 0;
    public static final int COMMUNICATON     = 1;
    public static final int CONTROLLER_STATE = 2;
    public static final int SWITCH_STATE     = 3;
    public static final int APPAGENT_REPLY   = 4;
    public static final int LOGIC            = 7;
    
    public ResultAnalyzer() {
    	
    }
   /* 
    public boolean checkUnknown() {
        boolean isSuccess = false;
        String fuzzingResult = "";
        if (this.checkControllerState()) {
            isSuccess = true;
            fuzzingResult += "Controller Shutdown\n";
        }

        if (this.checkSwitchState()) {
            isSuccess = true;
            fuzzingResult += "Switch Shutdown\n";
        }

        if (this.checkSwitchState()) {
            isSuccess = true;
            fuzzingResult += "Switch Shutdown\n";
        }

        if (isSuccess) {
            log.info("Success");
        }

        return true;
    }
    
    public String generateFlow(String proto) {
        hm.write(proto);
        String result = hm.read();
        return result;
    }
    
    public boolean checkCommunication(String in) {
        if (in.contains("Unreachable")) {
            log.info("* Result | Ping response host unreachable");
        } else if (in.contains("100%")) {
            log.info("100% Packet loss");
        } else {
            return false;
        }
        return true;
    }
    
    public boolean checkLatency(String before, String after) {
        if (before.contains("100%") || after.contains("100%")) {
            return true;
        }

        int idx = before.indexOf("min");
        before = before.substring(idx);

        StringTokenizer str = new StringTokenizer(before, "/");
        for (int i = 0; i < 4; i++)
            str.nextToken();
        before = str.nextToken();

        idx = after.indexOf("min");
        after = after.substring(idx);

        str = new StringTokenizer(after, "/");
        for (int i = 0; i < 4; i++)
            str.nextToken();
        after = str.nextToken();

        int beforeInt = (int) (Double.parseDouble(before) * 1000);
        int afterInt = (int) (Double.parseDouble(after) * 1000);

        log.info("Latency (ms) before: " + before + " < After: " + after);
        log.info("Threshold (ms) : " + Double.parseDouble(before) * 2);

        if ((beforeInt * 2) < afterInt) {
            return true;
        } else {
            return false;
        }
    }
    
    public boolean checkControllerState() {
    	
    	return false;
    }
    
    public boolean checkSwitchState() {
        Process temp = null;
        String tempS = "";
//        int switchCnt = controllerm.getSwitchCounter();
        int switchCnt =  SwitchConnectingWithController;
        int cnt = controllerm.isConnectedSwitch(false);

        if (switchCnt != cnt)
            log.info("switchCnt="+switchCnt+",isConnectedSwitch="+cnt+"-->Switch diconnected");
        else {
            log.info("switchCnt="+switchCnt+",isConnectedSwitch="+cnt+"-->Switches NOT disconnected");
            return false;
        }

        return true;
    }
    */
}
